package be.scond.cartpool.model;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User {
	
    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key; 

    @Persistent
    private Group group;

    @Persistent
	private String email;
    
    @Persistent
    private String password;

	@Persistent
	private String name;

	@Persistent
	private BigDecimal saldo;
	
	@NotPersistent
	private BigDecimal tempSaldo;
	
	@Persistent
	private boolean confirmed = false; 
	
	public User(){		
	}
	
	public String toXmlString(){
		String str = "";
		str += "<user>";
		str += "<key>"+KeyFactory.keyToString(key)+"</key>";
		str += "<name>"+name+"</name>";
		str += "<email>"+email+"</email>";
		str += "<confirmed>"+confirmed+"</confirmed>";
		NumberFormat form = new DecimalFormat("####0.00");        
		str += "<saldo>"+form.format(saldo)+"</saldo>";
		//str += "<saldo>"+saldo+"</saldo>";
		str += "<groupKey>"+KeyFactory.keyToString(group.getKey())+"</groupKey>";		
		str += "</user>";
		return str;
	}

	public Key getKey() {
		return key;
	}
	public void setKey(Key key) {
		this.key = key;
	}

	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public BigDecimal getSaldo() {
		return saldo;
	}
	public void setSaldo(BigDecimal saldo) {
		this.saldo = saldo;
	}

	public BigDecimal getTempSaldo() {
		return tempSaldo;
	}
	public void setTempSaldo(BigDecimal tempSaldo) {
		this.tempSaldo = tempSaldo;
	}

	public Group getGroup() {
		return group;
	}
	public void setGroup(Group group) {
		this.group = group;
	}
	
	public boolean isConfirmed() {
		return confirmed;
	}
	public void setConfirmed(boolean confirmed) {
		this.confirmed = confirmed;
	}

}
